package com.syzsn.springcloud.order.controller;

import com.alibaba.fastjson.JSON;
import com.syzsn.springcloud.common.entity.Order;
import com.syzsn.springcloud.common.entity.Product;
import com.syzsn.springcloud.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private OrderService orderService;

    @GetMapping("/order/prod/{pid}")
    public Order order(@PathVariable("pid") Integer pid){
        log.info(">> 客户下单，这时候要调用商品微服务查询商品信息");

        Product product = restTemplate.getForObject("http://localhost:9002/product/"+pid, Product.class);

        log.info(JSON.toJSONString(product));

        return new Order();
    }
}
